import random as rd
from function import Select
import time
import matplotlib.pyplot as plt

if __name__ == "__main__":
    while True:
        tmp_in = input("(退出请输入任意非数字字符)\n请输入要测试的数据量（整数）：")
        try:
            tmp_size = int(tmp_in)
            tmp_array = [rd.randint(-99999, 99999) for _ in range(tmp_size)]
            x = []
            y = []
            step = 1
            if tmp_size > 20:
                step = tmp_size // 20
            item = step
            while item < tmp_size:
                x.append(item)  # 第item+1 小
                start = time.time()
                Select(tmp_array, 0, tmp_size - 1, item)  # 选择 第item+1 小
                cost = time.time() - start
                y.append(cost)
                item += step
            print(x, "\ncost: ", y)
            plt.plot(x, y, label='costLine')
            plt.title('analysis')
            plt.xlabel('X the Xth min')
            plt.ylabel('Y Select Xth min cost')
            plt.legend()
            plt.show()
        except Exception:
            print("输入错误！\t退出程序")
            exit()
